package com.moon.robot.mapper;



import com.forte.qqrobot.anno.depend.Beans;


import com.moon.robot.pojo.Reply;
import org.apache.ibatis.annotations.*;


import java.util.List;

/**
 * 一个十分简单的Mapper
 * 这个mapper中出现的表：qq_message中只有一个字段：msg
 *
 * @author ForteScarlet <[email]ForteScarlet@163.com>
 * @since JDK1.8
 **/
@Mapper
@Beans

public interface MessageMapper {

    /**
     * 插入一条数据
     */

    @Insert("INSERT INTO reply(msg,answer,vague,addqq) VALUES(#{reply.msg},#{reply.answer},#{reply.vague},#{reply.addqq})")
    @SelectKey(keyProperty = "reply.id", before = false, resultType = Integer.class, statement = "select LAST_INSERT_ID()")
    int insertNewMsg(@Param("reply") Reply reply);


    @Select("SELECT * FROM reply WHERE msg = #{msg} and vague=0 ORDER BY msg")
    List<Reply> exactSelectMsg(String msg);

    @Select("SELECT id,msg FROM reply WHERE vague=1")
    List<Reply> SelectAllVague();

    /*@Options(useGeneratedKeys=true,keyProperty = "id")*/
    @Select("SELECT answer FROM reply WHERE id=#{id}")
    String selectAnswerById(Integer id);

    @Select("SELECT * FROM reply WHERE msg like CONCAT('%',#{s},'%')")
    List<Reply> selMsgByKey(String s);

    @Delete("DELETE FROM reply WHERE id = #{id}")
    Integer delMsgByID(Integer id);


    @Insert("INSERT INTO emoji(url) VALUES(#{url})")
    Integer addEmoji(String url);

    @Select("SELECT url FROM emoji WHERE url=#{url}")
    List<String> selectEmoji(String url);

    @Insert("INSERT INTO logss(logss) VALUES(#{logss})")
    int insertLOG(String logss);

}
